package com.walterlife.dp.FlyweightDP;

import java.util.HashMap;

import org.apache.log4j.Logger;

public class ShapeFactory {
    private static Logger logger = Logger.getLogger(Line.class);

    private static HashMap<ShapeType, Shape> shapes = new HashMap<ShapeType, Shape>();
    
    public static Shape getShape(ShapeType shapeType) {
        Shape shape = shapes.get(shapeType);

        if(shape == null) {
            if(ShapeType.OVAL_FILL.equals(shapeType)) {
                shape = new Oval(true);
            } else if(ShapeType.OVAL_NOT_FILL.equals(shapeType)) {
                shape = new Oval(false);
            } else if(ShapeType.LINE.equals(shapeType)) {
                shape = new Line();
            } else {
                logger.error("shapeType " + shapeType + "not exist!!!");
            } 
            shapes.put(shapeType, shape);
        } 
        return shape;
    } 

    public static enum ShapeType {
        OVAL_FILL, 
        OVAL_NOT_FILL, 
        LINE;
    } 
}
